let startBtn = document.querySelector(".startBtn");
let prizeCell = document.querySelectorAll(".drawBox div:not(.startBtn)");
let win = document.querySelector(".win");
let win1 = document.querySelector(".win1");
let index = 0;
let targetIndex = 86;
let timer;
let second = 200;
let isRun = true; //开关

/**
 * 开始抽奖基础版
 */
// startBtn.addEventListener("click", function() {
// timer = setInterval(function() {

//     if (index) {
//         prizeCell[(index - 1) % 8].classList.remove("active");
//     }

//     prizeCell[index % 8].classList.add("active");
//     if (index == targetIndex) {
//         clearInterval(timer);
//     }
//     index++;
//     console.log(index);
// }, 200)
// })

console.log(prizeCell[0].firstElementChild);


/**
 * 开始抽奖(升级版)
 */
startBtn.addEventListener("click", function() {
    if (isRun) { //为true
        isRun = false;
        run();
    }


})

function run() {
    setTimeout(function() {
        if (index) {
            prizeCell[(index - 1) % 8].classList.remove("active");
        }

        prizeCell[index % 8].classList.add("active");

        if (index < targetIndex) {
            run();
        } else {
            isRun = true;
        }
        win1.innerHTML = prizeCell[index % 8].lastElementChild.innerHTML;
        win.innerHTML = prizeCell[index % 8].firstElementChild.outerHTML;
        index++;

        if (second > 30 && index < 20) {
            //加速
            second -= 20;
        } else if (index > 65) {
            //减速
            second += 15;
        }
    }, second)
}